package net.wanglu.www.zzz.rule.artcl;

import java.util.regex.Pattern;

import net.wanglu.www.zzz.rule.BadEgg;
import net.wanglu.www.zzz.rule.Rule;
import net.wanglu.www.zzz.service.se.np._NPTuple;
import edu.stanford.nlp.ling.TaggedWord;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.tregex.TregexPattern;

public class Mountains extends _ArticleRule {

	public Pattern Mountains = Pattern.compile("\\b[Mm]ountains\\b");
	public Pattern Massif = Pattern.compile("\\b[Mm]assif\\b");
	public Pattern Mount = Pattern.compile("\\b[Mm]ount\\b");
	public Pattern Mountain = Pattern.compile("\\b[Mm]ountain\\b");
	public Pattern Peak = Pattern.compile("\\b[Pp]eak\\b");
	public Pattern NoDT = Pattern.compile("\\bAïr Massif\\b|\\bAir of Niger\\b|\\bKiyanja\\b|\\bChappal Waddi\\b|\\bEmi Koussi\\b|\\bRas Dashen\\b|\\bRas Dashan\\b|\\bRas Dejen\\b|\\bTafelberg\\b|\\bTenerife\\b|\\bThabana Ntlenyana\\b|\\bToubkal\\b|\\bTubkal\\b|\\bDome A\\b|\\bDome Argus\\b|\\bVinson Massif\\b|\\bAnnapurna\\b|\\bChurdhar Sanctuary\\b|\\bCho Oyu\\b|\\bJomolhari\\b|\\bChomolhari\\b|\\bSagarmatha\\b|\\bChomolungma\\b|\\bKamet\\b|\\bKangchenjunga\\b|\\bKula Kangri\\b|\\bLhotse\\b|\\bMachapuchare\\b|\\bMachapuchre\\b|\\bMakalu\\b|\\bManaslu\\b|\\bMelungtse\\b|\\bNamcha Barwa\\b|\\bNanda Devi\\b|\\bNanga Parbat\\b|\\bPumori\\b|\\bShishapangma\\b|\\bShivling\\b|\\bKangri\\b|\\bHimalaya\\b|\\bIstor-o-Nal\\b|\\bNoshaq\\b|\\bNowshak\\b|\\bSaraghrar\\b|\\bTirich Mir\\b|\\bTerich Mir\\b|\\bTerichmir\\b|\\bTurch Mir\\b|\\bBaintha Brakk\\b|\\bKarakorum\\b|\\bDiran\\b|\\bDisteghil Sar\\b|\\bDistaghil Sar\\b|\\bGasherbrum I\\b|\\bGasherbrum II\\b|\\bGasherbrum III\\b|\\bGasherbrum IV\\b|\\bGasherbrum V\\b|\\bChhogori\\b|\\bQogir\\b|\\bKetu\\b|\\bKechu\\b|\\bKanjut Sar\\b|\\bKhunyang Chhish\\b|\\bKunyang Chhish\\b|\\bMalubiting\\b|\\bMalubiting West\\b|\\bMasherbrum\\b|\\bMuztagh Tower\\b|\\bMustagh Tower\\b|\\bPassu Sar\\b|\\bPassu Sar\\b|\\bPassu I\\b|\\bRakaposhi\\b|\\bSia Kangri\\b|\\bSaltoro Kangri\\b|\\bSangemarmar Sar\\b|\\bSangemar Mar\\b|\\bSang-e-Marmar\\b|\\bSangemarmur\\b|\\bSkil Brum\\b|\\bSkilbrum\\b|\\bTirich Mir\\b|\\bTerich Mir\\b|\\bTerichmir\\b|\\bTurch Mir\\b|\\bTrango Towers\\b|\\bUltar Sar\\b|\\bUltar\\b|\\bUltar II\\b|\\bBojohagur Duanasir II\\b|\\bAltay\\b|\\bAltai\\b|\\bMönkh KHairkhan\\b|\\bTsambagarav\\b|\\bSutai\\b|\\bSutay Uul\\b|\\bChangbai\\b|\\bPaektu\\b|\\bBaektu\\b|\\bAnamudi\\b|\\bAnaimudi\\b|\\bMeesapulimala\\b|\\bDoddabetta\\b|\\bMullaiahnagiri\\b|\\bMullayangiri\\b|\\bMullainagiri\\b|\\bKudremukh\\b|\\bKuduremukha\\b|\\bTadiandamol\\b|\\bPushpagiri\\b|\\bKumara Parvatha\\b|\\bPidurutalagala\\b|\\bGuru Shikhar\\b|\\bHkakabo Razi\\b|\\bPuncak Jaya\\b|\\bCarstensz Pyramid\\b|\\bFansipan\\b|\\bPhou Bia\\b|\\bDoi Inthanon\\b|\\bPhnom Aural\\b|\\bBukit Pagon\\b|\\bBukit Timah\\b|\\bPhou Bia\\b|\\bDoi Inthanon\\b|\\bPhnom Aural\\b|\\bBukit Pagon\\b|\\bBukit Timah\\b|\\bKhao Luang\\b|\\bNgga Pulu\\b|\\bPuncak Mandala\\b|\\bJulianatop\\b|\\bPuncak Trikora\\b|\\bKanlaon Volcano\\b|\\bKanla-on\\b|\\bCanlaon\\b|\\bHuangshan\\b|\\bKawa Garbo\\b|\\bKhawa Karpo\\b|\\bKlyuchevskaya Sopka\\b|\\bKongur Tagh\\b|\\bMuztagh Ata\\b|\\bMuztagata\\b|\\bNoshaq\\b|\\bNowshak\\b|\\bOtgontenger\\b|\\bMonkh Saridag\\b|\\bPiz Bernina\\b|\\bPiz Corvatsch\\b|\\bHoher Dachstein\\b|\\bGroßvenediger\\b|\\bHochkönig\\b|\\bPiz Kesch\\b|\\bLyskamm\\b|\\bMont Blanc\\b|\\bMont Blanc de Courmayeur\\b|\\bMont Blanc du Tacul\\b|\\bCristallo\\b|\\bMonte Rosa\\b|\\bPiz Morteratsch\\b|\\bNordend\\b|\\bOrtler\\b|\\bMont Pelvoux\\b|\\bRigi\\b|\\bPiz Palü\\b|\\bSäntis\\b|\\bTitlis\\b|\\bTraunstein\\b|\\bTriglav\\b|\\bWildspitze\\b|\\bGran Sasso d'Italia\\b|\\bBesna Kobila\\b|\\bBelasica\\b|\\bBistra\\b|\\bBjelašnica\\b|\\bCeloica\\b|\\bČvrsnica\\b|\\bDešat\\b|\\bDinara\\b|\\bGaličica\\b|\\bHymettus\\b|\\bIgman\\b|\\bJakupica\\b|\\bJablanica\\b|\\bKopaonik\\b|\\bKožuf\\b|\\bTzena\\b|\\bMaglić\\b|\\bOrjen\\b|\\bOsogovo\\b|\\bPrenj\\b|\\bProkletije\\b|\\bRila\\b|\\bStogovo\\b|\\bVitosha\\b|\\bZlatibor\\b|\\bGerlachovský štít\\b|\\bKékes\\b|\\bDykh-Tau\\b|\\bDykhtau\\b|\\bShkhara\\b|\\bKoshtan-Tau\\b|\\bDzhangi-Tau\\b|\\bJangi-Tau\\b|\\bUshba\\b|\\bFeldberg\\b|\\bMoncayo\\b|\\bHekla\\b|\\bÖræfajökull\\b|\\bSnæfellsjökull\\b|\\bCarrauntoohil\\b|\\bCarrantuohil\\b|\\bBeenkeragh\\b|\\bBenkeeragh\\b|\\bCaher\\b|\\bLugnaquilla\\b|\\bLugnaquillia\\b|\\bGaltymore\\b|\\bGalteemore\\b|\\bSlieve Donard\\b|\\bMweelrea\\b|\\bNephin\\b|\\bNefin\\b|\\bCroagh Patrick\\b|\\bSlieve Gullion\\b|\\bMuckish\\b|\\bMøllehøj\\b|\\bYding Skovhøj\\b|\\bEjer Bavnehøj\\b|\\bHalti\\b|\\bRidnitsohkka\\b|\\bKovddoskaisi\\b|\\bGaldhøpiggen\\b|\\bGlittertind\\b|\\bStore Skagastølstind\\b|\\bSkarstind\\b|\\bVesle Galdhøpiggen\\b|\\bVeslepiggen\\b|\\bSurtningssue\\b|\\bSurtningssui\\b|\\bKebnekaise\\b|\\bÁhkká\\b|\\bKaskasatjåkka\\b|\\bSarektjåkkå\\b|\\bÅreskutan\\b|\\bHalleberg\\b|\\bHunneberg\\b|\\bKinnekulle\\b|\\bBen Nevis\\b|\\bSnowdon\\b|\\bScafell Pike\\b|\\bCross Fell\\b|\\bPeny Fan\\b|\\bSlieve Donard\\b|\\bPlynlimon\\b|\\bKinder Scout\\b|\\bBeerenberg\\b|\\bÖræfajökull\\b|\\bCumbre Vieja\\b|\\bEyjafjallajökull\\b|\\bKatla\\b|\\bHekla\\b|\\bSnæfellsjökull\\b|\\bStromboli\\b|\\bKates Needle\\b|\\bBishop's Mitre\\b|\\bBlue Knob\\b|\\bBroken Top\\b|\\bCamel's Hump\\b|\\bCloudveil Dome\\b|\\bCrested Butte\\b|\\bCrestone Needle\\b|\\bDevils Thumb\\b|\\bDevils Tower\\b|\\bGrand Teton\\b|\\bHalf Dome\\b|\\bMauna Loa\\b|\\bNewberry Volcano\\b|\\bThree Fingered Jack\\b|\\bWolf's Head\\b|\\bFalls Creek\\b|\\bBluff Knoll\\b|\\bUluru\\b|\\bMauna Kea\\b|\\bHaleakalā\\b|\\bMauna Loa\\b|\\bSemeru\\b|\\bRaung\\b|\\bBuyu Balease\\b|\\bNevado Sajama\\b|\\bIllimani\\b|\\bJanq'u Uma\\b|\\bIllampu\\b|\\bHuayna Potosí\\b|\\bChachakumani\\b|\\bPico da Neblina\\b|\\bPico da Bandeira\\b|\\bPedra da Mina\\b|\\bPico das Agulhas Negras\\b|\\bSerra dos Órgãos\\b|\\bPico Cristóbal Colón\\b|\\bRitacuba Blanco\\b|\\bNevado del Huila\\b|\\bNevado del Tolima\\b|\\bSanta Isabel\\b|\\bCumbal\\b|\\bPuracé\\b|\\bCerro Negro de Mayasquer\\b|\\bGaleras\\b|\\bAzufral\\b|\\bChimborazo\\b|\\bCotopaxi\\b|\\bCayambe\\b|\\bAntisana\\b|\\bEl Altar\\b|\\bSangay\\b|\\bTungurahua\\b|\\bCarihuairazo\\b|\\bCotacachi\\b|\\bSincholagua Volcano\\b|\\bCorazón\\b|\\bPichincha\\b|\\bChiles\\b|\\bRumiñawi\\b|\\bImbabura\\b|\\bAtacazo\\b|\\bPasochoa\\b|\\bSumaco\\b|\\bReventador\\b|\\bCerro Peró\\b|\\bHuascarán\\b|\\bSalcantay\\b|\\bCerro Bravo\\b|\\bCerro Catedral\\b|\\bPico Bolívar\\b|\\bAconcagua\\b|\\bNevado Ojos del Salado\\b|\\bPissis\\b|\\bLlullaillaco\\b|\\bMercedario\\b|\\bCerro El Plomo\\b|\\bSan Valentin\\b|\\bLanín\\b|\\bTronador\\b|\\bFitz Roy\\b|\\bCerro Torre\\b|\\bAntuco\\b|\\bVillarrica\\b|\\bSarmiento\\b|\\bRoque de los Muchachos\\b|\\bPico de São Tomé\\b");
	public Pattern The = Pattern.compile("\\bIlliniza\\b|\\bNevado El Cisne\\b|\\bNevado del Quindío\\b|\\bNevado del Ruiz\\b|\\bSierra Nevada de Santa Marta\\b|\\bCordillera Real\\b|\\bGreat Dividing Range\\b|\\bAustralian Alps\\b|\\bThree Sisters\\b|\\bMaroon Bells\\b|\\bCirque of the Towers\\b|\\bGolden Hinde\\b|\\bCheviot\\b|\\bFichtelberg\\b|\\bBrocken\\b|\\bRhodopes\\b|\\bPirin\\b|\\bPanachaiko\\b|\\bBalkan Peninsula\\b|\\bBalkans\\b|\\bZumsteinspitze\\b|\\bZugspitze\\b|\\bZinalrothorn\\b|\\bWildstrubel\\b|\\bWildhorn\\b|\\bWetterhorn\\b|\\bWeissmies\\b|\\bWeisshorn\\b|\\bUntersberg\\b|\\bTödi\\b|\\bStrahlhorn\\b|\\bSignalkuppe\\b|\\bSchreckhorn\\b|\\bSchneeberg\\b|\\bSchlern\\b|\\bRimpfischhorn\\b|\\bRheinwaldhorn\\b|\\bOstspitze\\b|\\bOber Gabelhorn\\b|\\bNesthorn\\b|\\bNapf\\b|\\bNadelhorn\\b|\\bMönch\\b|\\bMatterhorn\\b|\\bLenzspitze\\b|\\bLauteraarhorn\\b|\\bLagginhorn\\b|\\bHimalayas\\b|\\bHindu Kush\\b|\\bKarakoram\\b|\\bOgre\\b|\\bBuni Zom\\b|\\bAllalinhorn\\b|\\bAlphubel\\b|\\bBalmhorn\\b|\\bBietschhorn\\b|\\bBishorn\\b|\\bBlüemlisalp\\b|\\bBreithorn\\b|\\bDammastock\\b|\\bDent Blanche\\b|\\bDent du Géant\\b|\\bDent d'Hérens\\b|\\bDents du Midi\\b|\\bDiablerets\\b|\\bEiger\\b|\\bDom\\b|\\bGross Fiescherhorn\\b|\\bFinsteraarhorn\\b|\\bGornergrat\\b|\\bGran Paradiso\\b|\\bGrand Combin\\b|\\bGrandes Jorasses\\b|\\bGrossglockner\\b|\\bJungfrau\\b|\\bKlein Matterhorn\\b");
	
	@Override
	public Object applicable(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		_NPTuple npt = (_NPTuple) objects[1];
		Tree NP = npt.getNP();
		if ( NP.depth() != 2) return Rule.Inapplicable;//如果不是叶子节点的父母则不符合要求
		TaggedWord headword = npt.getHeadword();
		if ( headword.tag().startsWith("NN")) {
			return Rule.Applicable;//如果中心词是名词则符合要求，否则不符合
		} else {
			return Rule.Inapplicable;
		}
	}

	@Override
	public Object deviseRightSolution(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object examine(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		if ( this.applicable(objects) == Rule.Inapplicable) return Rule.Inapplicable;
		
		_NPTuple npt = (_NPTuple) objects[1];
		Tree NP = npt.getNP();

		/*
		 * 名词短语中
		 */
		sb.clear();
		for( TaggedWord tw : NP.taggedYield()) {
			sb.append(tw.word()).append(" ");
		}
		
		if ( this.Mountains.matcher(sb.toString().trim()).find()) {
			if ( sb.toString().trim().startsWith("the") || sb.toString().trim().startsWith("The")) {
				return null;
			} else {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;	
			}			
		} else if ( this.Massif.matcher(sb.toString().trim()).find()) {
			if ( sb.toString().trim().startsWith("the") || sb.toString().trim().startsWith("The")) {
				return null;
			} else {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;	
			}			
		} else if ( this.Mount.matcher(sb.toString().trim()).find()) {
			TregexPattern pattern = TregexPattern.compile("/\\bNP\\b/</\\bDT\\b/");
			if ( pattern.matcher(NP).find()) {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;					
			} else {
				return null;
			}
		} else if ( this.Mountain.matcher(sb.toString().trim()).find()) {
			TregexPattern pattern = TregexPattern.compile("/\\bNP\\b/</\\bDT\\b/");
			if ( pattern.matcher(NP).find()) {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;					
			} else {
				return null;
			}
		} else if ( this.Peak.matcher(sb.toString().trim()).find()) {
			TregexPattern pattern = TregexPattern.compile("/\\bNP\\b/</\\bDT\\b/");
			if ( pattern.matcher(NP).find()) {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;					
			} else {
				return null;
			}
		} else if ( this.The.matcher(sb.toString().trim()).find()) {
			if ( sb.toString().trim().startsWith("the") || sb.toString().trim().startsWith("The")) {
				return null;
			} else {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;	
			}						
		} else if ( this.NoDT.matcher(sb.toString().trim()).find()) {
			TregexPattern pattern = TregexPattern.compile("/\\bNP\\b/</\\bDT\\b/");
			if ( pattern.matcher(NP).find()) {
				BadEgg egg = new BadEgg();
				egg.whereIsWrong = NP;
				egg.setProperty(BadEgg.Error);
				egg.setViolatedRule(this);
				return egg;					
			} else {
				return null;
			}			
		} else {
			return Rule.Inapplicable;
		}
	}

	@Override
	public Object whyItsWrong(Object... objects) throws Exception {
		// TODO Auto-generated method stub
		sb.append("<p>");
		sb.append("山脉前面一般要加定冠词。");
		sb.append("</p>");			
		return sb.toString();
	}
}
